package may;

import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @author ：冯涛滔
 * @date ：Created in 2020-5-29 8:10
 * @description： 贪心使我快乐
 * @modified By：
 * @version:
 */
public class May29 {
    /**
     * create by: 冯涛滔
     * description: https://leetcode-cn.com/problems/maximum-number-of-events-that-can-be-attended/ 最多可以参加的会议数目
     * 先排序然后去参加最短的
     * create time: 2020-5-28 18:33
     * @params [events]
     * @return int
     */
    public static int maxEvents(int[][] events) {
        //首先排序：开始时间小的在前。这样是方便我们顺序遍历，把开始时间一样的都放进堆
        Arrays.sort(events, (o1, o2) -> o1[0] - o2[0]);
        //小顶堆 数字最小的会在最上面
        PriorityQueue<Integer> pq = new PriorityQueue<>();
        //结果、开始时间、events下标、有多少组数据
        int res = 0, last = 1, i = 0, n = events.length;
        while (i < n || !pq.isEmpty()) {
            //将start相同的会议都放进堆里
            while (i < n && events[i][0] == last) {
                pq.offer(events[i++][1]);
            }
            //pop掉当前天数之前的 //过期了的就不要了
            while (!pq.isEmpty() && pq.peek() < last) {
                pq.poll();
            }
            //顶上的就是俺们要参加的 //当天参加了一个
            if (!pq.isEmpty()) {
                pq.poll();
                res++;
            }
            last++;
        }
        return res;
    }


    public static void main(String[] args) {
        print1();
        print2();
        print3(50);
        print4();
        print5();
    }
    public static void print1(){
        String a = "ABCDEFG";
        System.out.println(a.substring(2, 4));
        System.out.println(a.substring(1,2));
        System.out.println(a.substring(5,6));
    }
    public static void print2(){
        System.out.println(Math.abs(-1));
    }
    public static void print3(int n){
        Set<int[]> set = new HashSet<>();
        int i = 1;
        while(set.size()<n){
            boolean add = set.add(new int[]{i, (int) (Math.floor(Math.random() * (n + 1 - 1)) + 1)});
            if(add)i++;
        }
        for (int[] ints : set) {
            System.out.println(Arrays.toString(ints));
        }
    }
    public static void print4(){
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
        String time = format.format(Calendar.getInstance().getTime());
        System.out.println(time);
    }
    public static void print5(){
        long start = System.currentTimeMillis();
        int num=0;
        GregorianCalendar year = new GregorianCalendar();
        for (int i=2000;i<2100;i++) {
            if (year.isLeapYear(i)){
                System.out.print(i+"  ");
            }
        }
        System.out.println();
        long end = System.currentTimeMillis();
        System.out.println((end-start)+"ms");
    }




}
